num= input ()
 
if len(str(num)) != 4:
    print(0)
else:
    prime_found = False
    for length in range(4, 0, -1):
        if prime_found:
            break
        for i in range(4 - length + 1):
            abc = int(str(num)[i:i+length])
            if abc < 2:
                continue
            for j in range(2, int(abc**0.5) + 1):
                if abc % j == 0:
                    break
            else:
                print(abc)
                prime_found = True
                break
    if not prime_found:
        print(0)
